﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BingVis.SilverlightClient.Common;

namespace BingVis.SilverlightClient.GoogleTransit
{
    public class TransitRouteLoader : TransitLoaderBase<ITransitRoute>, ITransitRouteLoader
    {
        private IEnumerable<ITransitTrip> _trips;

        public TransitRouteLoader(IGTFSFile file)
            : this(file, new List<ITransitTrip>())
        {
            
        }

        public TransitRouteLoader(IGTFSFile file, IEnumerable<ITransitTrip> trips)
            : base(file)
        {
            _trips = trips;
        }

        public override void ProcessItem(ICSVLine line)
        {
            int type = 0;
            int.TryParse(line["route_type"], out type);

            var item = new TransitRoute(_trips.Where(t => t.RouteId == line["route_id"]))
            {
                Id = line["route_id"],
                ShortName = line["route_short_name"],
                LongName = line["route_long_name"],
                Description = line["route_desc"],
                Url = line["route_url"],
                ColorHex = line["route_color"],
                AgencyId = line["agency_id"],
                Type = type,
            };

            Items.Add(item);
            OnItemLoaded(item);
        }
    }
}
